﻿using System.IO;
using Catel.Articles.Base.Data.Attributes;
using Catel.Articles.Base.UI;
using System.Windows.Markup;

namespace Catel.Articles._02___WPF_controls.Examples.StackGrid
{
    [Example("StackGrid", "Example of the StackGrid control",
        LongDescription = @"Although the example looks crappy (I am not a designer), it shows the power of the StackGrid.

You don't have to specify the Grid.Row and Grid.Column attached properties.

Remember the times that you want to insert a grid and you had to increase all the numbers? From now on, use the StackGrid!",
        SourceFileName = "/Examples/StackGrid/Code.txt",
        ImageUri = "/Examples/StackGrid/Screenshot.png",
        ClickHandlerName = "ShowExample")]
    public class Example
    {
        /// <summary>
        /// Shows the example.
        /// </summary>
        private static void ShowExample()
        {
            // Declare variables
            Windows.Controls.StackGrid stackGrid = null;

            // Create context
            ParserContext context = new ParserContext();

            // Load xaml namespaces differently
            context.XamlTypeMapper = new XamlTypeMapper(new string[] { });
            context.XamlTypeMapper.AddMappingProcessingInstruction("Controls", "Catel.Windows.Controls", "Catel.Windows");

            // Now load the xmlns dictionary
            context.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
            context.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml");
            context.XmlnsDictionary.Add("Controls", "Controls");

            // Load control via xaml
            using (Stream stream = new FileStream("Examples\\StackGrid\\Code.txt", FileMode.Open))
            {
                stackGrid = (Windows.Controls.StackGrid)XamlReader.Load(stream, context);
            }

            // Show control
            ExampleHelper.ShowControlInWindow(stackGrid, null, 0, 0, 0, 0);
        }
    }
}
